﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;

namespace Developmentalmadness.Web.UI.AjaxAbstractions
{
    /// <summary>
    /// A wrapper class for System.Web.UI.ClientScriptManager
    /// </summary>
    internal class ClientScriptManagerWrapper : ClientScriptManagerBase
    {
        private ClientScriptManager _manager;
        private Page _page;

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="page">the current System.Web.UI.Page object</param>
        public ClientScriptManagerWrapper(Page page)
        {
            //store reference to Page
            _page = page;

            //store reference to ClientScript for easier access
            _manager = page.ClientScript;
        }

        /// <summary>
        /// Because we're using WebForms model here, we will immediately add all
        /// registered Css includes to the page's head element
        /// </summary>
        /// <param name="url"></param>
        protected override void RenderClientCssInclude(string url)
        {
            //create link control
            HtmlLink css = new HtmlLink();
            css.Attributes.Add("type", "text/css");
            css.Attributes.Add("rel", "stylesheet");
            css.Href = url;

            //add the control to the page's head element
            _page.Header.Controls.Add(css);
        }

        public override string GetCallbackEventReference(Control control, string argument, string clientCallback, string context)
        {
            return _manager.GetCallbackEventReference(control, argument, clientCallback, context);
        }

        public override string GetCallbackEventReference(Control control, string argument, string clientCallback, string context, bool useAsync)
        {
            return _manager.GetCallbackEventReference(control, argument, clientCallback, context, useAsync);
        }

        public override string GetCallbackEventReference(string target, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync)
        {
            return _manager.GetCallbackEventReference(target, argument, clientCallback, context, clientErrorCallback, useAsync);
        }

        public override string GetCallbackEventReference(Control control, string argument, string clientCallback, string context, string clientErrorCallback, bool useAsync)
        {
            return _manager.GetCallbackEventReference(control, argument, clientCallback, context, clientErrorCallback, useAsync);
        }

        public override string GetPostBackClientHyperlink(Control control, string argument)
        {
            return _manager.GetPostBackClientHyperlink(control, argument);
        }

        public override string GetPostBackClientHyperlink(Control control, string argument, bool registerForEventValidation)
        {
            return _manager.GetPostBackClientHyperlink(control, argument, registerForEventValidation);
        }

        public override string GetPostBackEventReference(PostBackOptions options)
        {
            return _manager.GetPostBackEventReference(options);
        }

        public override string GetPostBackEventReference(Control control, string argument)
        {
            return _manager.GetPostBackEventReference(control, argument);
        }

        public override string GetPostBackEventReference(PostBackOptions options, bool registerForEventValidation)
        {
            return _manager.GetPostBackEventReference(options, registerForEventValidation);
        }

        public override string GetPostBackEventReference(Control control, string argument, bool registerForEventValidation)
        {
            return _manager.GetPostBackEventReference(control, argument, registerForEventValidation);
        }

        public override string GetWebResourceUrl(Type type, string resourceName)
        {
            return _manager.GetWebResourceUrl(type, resourceName);
        }

        public override bool IsClientScriptBlockRegistered(string key)
        {
            return _manager.IsClientScriptBlockRegistered(key);
        }

        public override bool IsClientScriptBlockRegistered(Type type, string key)
        {
            return _manager.IsClientScriptBlockRegistered(type, key);
        }

        public override bool IsClientScriptIncludeRegistered(string key)
        {
            return _manager.IsClientScriptIncludeRegistered(key);
        }

        public override bool IsClientScriptIncludeRegistered(Type type, string key)
        {
            return _manager.IsClientScriptIncludeRegistered(type, key);
        }

        public override bool IsOnSubmitStatementRegistered(string key)
        {
            return _manager.IsOnSubmitStatementRegistered(key);
        }

        public override bool IsOnSubmitStatementRegistered(Type type, string key)
        {
            return _manager.IsOnSubmitStatementRegistered(type, key);
        }

        public override bool IsStartupScriptRegistered(string key)
        {
            return _manager.IsStartupScriptRegistered(key);
        }

        public override bool IsStartupScriptRegistered(Type type, string key)
        {
            return _manager.IsStartupScriptRegistered(type, key);
        }

        public override void RegisterArrayDeclaration(string arrayName, string arrayValue)
        {
            _manager.RegisterArrayDeclaration(arrayName, arrayValue);
        }

        public override void RegisterClientScriptBlock(Type type, string key, string script)
        {
            _manager.RegisterClientScriptBlock(type, key, script);
        }

        public override void RegisterClientScriptBlock(Type type, string key, string script, bool addScriptTags)
        {
            _manager.RegisterClientScriptBlock(type, key, script, addScriptTags);
        }

        public override void RegisterClientScriptInclude(string key, string url)
        {
            _manager.RegisterClientScriptInclude(key, url);
        }

        public override void RegisterClientScriptInclude(Type type, string key, string url)
        {
            _manager.RegisterClientScriptInclude(type, key, url);
        }

        public override void RegisterClientScriptResource(Type type, string resourceName)
        {
            _manager.RegisterClientScriptResource(type, resourceName);
        }

        public override void RegisterExpandoAttribute(string controlId, string attributeName, string attributeValue)
        {
            _manager.RegisterExpandoAttribute(controlId, attributeName, attributeValue);
        }

        public override void RegisterExpandoAttribute(string controlId, string attributeName, string attributeValue, bool encode)
        {
            _manager.RegisterExpandoAttribute(controlId, attributeName, attributeValue, encode);
        }

        public override void RegisterForEventValidation(string uniqueId)
        {
            _manager.RegisterForEventValidation(uniqueId);
        }

        public override void RegisterForEventValidation(PostBackOptions options)
        {
            _manager.RegisterForEventValidation(options);
        }

        public override void RegisterForEventValidation(string uniqueId, string argument)
        {
            _manager.RegisterForEventValidation(uniqueId, argument);
        }

        public override void RegisterHiddenField(string hiddenFieldName, string hiddenFieldInitialValue)
        {
            _manager.RegisterHiddenField(hiddenFieldName, hiddenFieldInitialValue);
        }

        public override void RegisterOnSubmitStatement(Type type, string key, string script)
        {
            _manager.RegisterOnSubmitStatement(type, key, script);
        }

        public override void RegisterStartupScript(Type type, string key, string script)
        {
            _manager.RegisterStartupScript(type, key, script);
        }

        public override void RegisterStartupScript(Type type, string key, string script, bool addScriptTags)
        {
            _manager.RegisterStartupScript(type, key, script, addScriptTags);
        }

        public override void ValidateEvent(string uniqueId)
        {
            _manager.ValidateEvent(uniqueId);
        }

        public override void ValidateEvent(string uniqueId, string argument)
        {
            _manager.ValidateEvent(uniqueId, argument);
        }
    }
}
